﻿<helpers:BindablePage
    x:Class="BalanceManager.Views.AddFundFlow"
    x:Name="addFundFlowPage"
    DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=AddFundFlowViewModel}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:vm="clr-namespace:BalanceManager.ViewModels"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:uic="clr-namespace:BalanceManager.UIControls"
    xmlns:bar="clr-namespace:BindableApplicationBar;assembly=BindableApplicationBar"
    xmlns:helpers="clr-namespace:BalanceManager.Helpers"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:converters="clr-namespace:BalanceManager.Helpers.Converters"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!-- Animated page transition -->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn" />
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn" />
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut" />
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut" />
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <helpers:BindablePage.Resources>
        <converters:FlowTypeToTextConverter x:Key="flowTypeConverter" />
    </helpers:BindablePage.Resources>
    
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <Grid Grid.Row="0" Margin="12,17,0,28">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="165*" />
                <ColumnDefinition Width="49*"/>
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=CurrentFundFlow.FlowType, Converter={StaticResource flowTypeConverter}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextLargeStyle}"/>
        </Grid>

        <StackPanel Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Text="Введите сумму" Style="{StaticResource PhoneTextSmallStyle}" />
            <uic:CurrencyTextBox Text="{Binding CurrentFundFlow.Amount, Mode=TwoWay, StringFormat=F2, UpdateSourceTrigger=Explicit}" FontSize="48" TextAlignment="Right" TextChanged="TextBox_TextChanged" Hold="TextBox_Hold" GotFocus="TextBox_GotFocus"  />
            
            <TextBlock Text="Выберите категорию" Style="{StaticResource PhoneTextSmallStyle}" />
            <Button Content="{Binding SelectedItemText}" Command="{Binding SelectCategoryCommand}" />
            
            <TextBlock Text="Дата" Style="{StaticResource PhoneTextSmallStyle}" />
            <toolkit:DatePicker Value="{Binding Path=CurrentFundFlow.Date, Mode=TwoWay}" HorizontalContentAlignment="Center" />

            <TextBlock Text="Недавно используемые" Style="{StaticResource PhoneTextSmallStyle}" />
            <ScrollViewer Height="400">
                <ItemsControl  x:Name="recentlyPanel" ItemsSource="{Binding RecentlyUsedItems}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button MaxWidth="300" Height="75" Content="{Binding Name}" Command="{Binding Path=DataContext.RecentlyItemUpdateCommand, ElementName=addFundFlowPage}" CommandParameter="{Binding Id}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </StackPanel>
    </Grid>

    <bar:Bindable.ApplicationBar>
        <bar:BindableApplicationBar>
            <bar:BindableApplicationBarButton Command="{Binding SaveCommand}" x:Name="btnSave" IconUri="/Images/save.png" Text="Сохранить" />
        </bar:BindableApplicationBar>
    </bar:Bindable.ApplicationBar>

</helpers:BindablePage>